import cv2
import numpy as np

img1 = cv2.imread('D:\\label.jpg')
img = cv2.pyrDown(img1)
# 高斯滤波，消除噪音
img = cv2.GaussianBlur(img, (5, 5), 0)
# 将图形进行二值化，用于后面的自适应阈值二值化
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
cv2.namedWindow('fushi', cv2.WINDOW_NORMAL)
cv2.namedWindow('pengzhang', cv2.WINDOW_NORMAL)
# 自适应阈值二值化
dst = cv2.adaptiveThreshold(gray, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C,  cv2.THRESH_BINARY, 11, 2)

# 使用一个1*1的卷积核
kernel = np.ones((1, 1), np.uint8)
# 腐蚀操作
dst = cv2.dilate(dst, kernel, iterations=-1)
cv2.imshow('fushi', dst)
# 膨胀操作
dst = cv2.erode(dst, kernel, iterations=1)
cv2.imshow('pengzhang', dst)

c = cv2.waitKey(0)
